package com.wanmao.test;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;


import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.wanmao.test.model.InstitutionModel;

import java.util.List;

import static com.wanmao.test.framgent.Framgent_Test_Search.getJsonStr;




public class InstitutionDetailActivity extends BaseActivity {

    private TextView tvFileName;
    private TextView tvProject;
    private TextView tvGist;
    private TextView tvAccording;
    private TextView tvRequire;
    private TextView tvResult;

    public static void startActivity(Context context, String fileName, InstitutionModel.TabsBean.ContentBean item) {
        Intent intent = new Intent(context, InstitutionDetailActivity.class);
        intent.putExtra("fileName", fileName);
        intent.putExtra("content", item);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_institution_detail);
        findViewById(R.id.img_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        InstitutionModel.TabsBean.ContentBean bean = getIntent().getParcelableExtra("content");

        if (null == bean) {
            List<InstitutionModel> list = new Gson().fromJson(getJsonStr(this, "biaozhunshuju1.json"), new TypeToken<List<InstitutionModel>>() {
            }.getType());
            bean = list.get(0).getTabs().get(0).getContent().get(0);
            Toast.makeText(this, "数据来自JSON", Toast.LENGTH_SHORT).show();
        }
        if (null == bean) {
            Toast.makeText(this, "数据错误", Toast.LENGTH_SHORT).show();
            finish();
        }

        tvFileName = (TextView) findViewById(R.id.tv_file_name);
        tvProject = (TextView) findViewById(R.id.tv_project);
        tvGist = (TextView) findViewById(R.id.tv_gist);
        tvAccording = (TextView) findViewById(R.id.tv_according);
        tvRequire = (TextView) findViewById(R.id.tv_require);
        tvResult = (TextView) findViewById(R.id.tv_result);

        tvFileName.setText(getIntent().getStringExtra("fileName"));
        tvProject.setText(bean.getProject());
        tvGist.setText(bean.getGist());
        tvAccording.setText(bean.getAccording());
        tvRequire.setText(bean.getRequire());
        tvResult.setText(bean.getResult());
    }


}
